﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Gallio.Framework;
using MbUnit.Framework;
using Netkk.Common.Models;
using Netkk.Library.Repositories;
using Netkk.Library.Services;
using Netkk.Library.Validation;

namespace Netkk.Tests.Contents
{
    [TestFixture]
    public class ContentsTest
    {
        private IContentService contentService;

        [SetUp]
        public void Startup()
        {
            ModelStateDictionary modelStateDictionary = new ModelStateDictionary();
            IValidationDictionary validationDictionary = new ModelStateWrapper(modelStateDictionary);
            contentService = new ContentService(validationDictionary, new ContentRepository());
        }

        [TearDown]
        public void Shutdown()
        {
        }

        [Test]
        [Row("Imprint")]
        [Row("About")]
        public void Schould_Return_A_Valid_Content_From_A_Given_Name(string name)
        {
            Content content = contentService.GetContentByName(name);

            Assert.IsNotNull(content);
        }

        [Test]
        [Row("Test")]
        [Row("MyPage")]
        public void Schould_Not_Return_A_Valid_Content_From_A_Given_Name(string name)
        {
            Content content = contentService.GetContentByName(name);

            Assert.IsNull(content);
        }

        [Test]
        public void Create_Select_And_Delete_A_Content()
        {
            string contentName = "TestPage";
            Content user = new Content
            {
                Name = contentName,
                PageTitle = "TestPage PageTitle",
                PageContent = "TestPage PageContent",
                PageDescription = "TestPage PageDescription",
                PageKeywords = "TestPage PageKeywords"
            };

            Assert.IsTrue(contentService.SaveContent(user), "Content wurde nicht erstellt");

            user = contentService.GetContentByName(contentName);

            Assert.IsNotNull(user, "Erstelter Content wurde nicht gefunden");

            contentService.DeleteContent(user);

            user = contentService.GetContentByName(contentName);

            Assert.IsNull(user, "Erstellter Content wurde nicht gelöscht");
        }

    }
}
